home *** CD-ROM | disk | FTP | other *** search
- /* fddisp.c file - display_page: display current page of file */
- #include "stdio.h"
- #include "cminor.h"
- #include "fdparm.h"
-
- extern char filename[] ;
- extern long filesize ; /* size of file in bytes */
- extern long top_of_page ; /* file position of top of page */
-
- /* special symbols to represent CR, LF, CTL-Z, & other ctl chars */
- #define PRT_CR 20
- #define PRT_LF 25
- #define PRT_CTLZ 17
- #define PRT_OTHER 22
- #define ASC_CTLZ 26
-
- int row ; /* current line of page */
- long start ;
-
-
- int display_page()
- {
- char block[ LINE_SIZE ] ;
- int nbytes ;
- int i ; /* index for loops */
-
- move_to(top_of_page) ; /* start at top of the page */
- /* write a header line */
- printf("\n FILE - %s POSITION - %1d FILE SIZE - %1d \n",
- filename, top_of_page, filesize) ;
- for( i=1 ; i < 80 ; i = i+1 ) /* write a border ilne of dashes */
- { putchar('-') ; }
-
- /* get chars from file until we've written (PAGE_SIZE) lines */
- /* or we've reached the end of the file */
- row = 1 ; /* starting row values */
- start = top_of_page ;
- while( row <= PAGE_SIZE )
- { nbytes = read_line(block,LINE_SIZE) ;
- if( nbytes <= 0 )
- break ;
- prtline(block,nbytes) ;
- start = start + nbytes ;
- row = row + 1 ;
- }
-
- while( row <= PAGE_SIZE ) /* pad out page if eof reached */
- { putchar('\n') ; row = row + 1 ; }
- for( i=1 ; i <= 80 ; i = i+1 ) /* write border line of dashes */
- { putchar('-') ; }
- }
-
-
- int prtline(block,nbytes) /* prints one line */
- char block[] ;
- int nbytes ;
- {
- int i ;
-
- printf("%81d | ",start) ; /* print file pos */
- for( i=1 ; i < LINE_SIZE ; i = i+1)/* print bytes in hex */
- { if ( i < nbytes )
- printf("%02x ",( tochar(block[i]) ) ) ;
- else printf(" ") ; /* out of data - fill in */
- }
-
- printf("| ") ;
-
- for( i=0 ; i < nbytes ; i = i+1 ) /* display ASCII form */
- { disp_char( tochar(block[i]) ) ; }
- putchar('\n') ;
- }
-
- int disp_char(c) /* display one char in ASCII */
- int c ; /* value of char to display */
- {
- /* classify the character and handle accordingly */
-
- if( isgraphic(c) ) /* ASCII graphic - display it */
- ;
- else if( c == '\n' ) /* newline (lf) - display symbol */
- c = PRT_LF ;
- else if( c == '\r' ) /* Carr. Return - display symbol */
- c = PRT_CR ;
- else if( c == ASC_CTLZ ) /* CTL-Z - display symbol */
- c = PRT_CTLZ ;
- else c = PRT_OTHER ; /* other char - display symbol */
-
- putchar(c) ;
- }
-
-
-
-